<link type="text/css" href="/admins/js/pagerView/pager-view.css" rel="stylesheet" />
<link type="text/css" href="/admins/js/jquery/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/admins/js/jquery/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="/admins/js/jquery/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript" src="/admins/js/pagerView/pager-view.js"></script>
<script type="text/javascript">
    $(function(){
    
        $.datepicker.setDefaults( $.datepicker.regional[ "zh-CN" ] );
        $( "#billboy #dateStart" ).datepicker({
            changeMonth: true,
            changeYear: true
        });
        $( "#billboy #dateEnd" ).datepicker({
            changeMonth: true,
            changeYear: true
        });
    });
</script>
<style>
    #billboy{
        font-size: 14px;
        width: 80%;
    }
    #userdetail{
        line-height: 36px;
        padding-left: 20px;
        padding-bottom: 10px;
        font-size: 16px;
    }
    #userdetail input{
        width: 80%;
        height: 20px;
        font-size: 16px;
    }
    #bf{
        background-color: #eee;
        text-align: right;
        width: 15%;
        height: 50px;
    }
    #cf{
        width: 35%;
    }
    select{
        font-size: 16px;
        height:24px;
    }
</style>
<?php
if($this->ma == 1){
    echo '<script language="javascript" type="text/javascript">alert("批次添加成功！");location.href = "/admini/manageuser/couponbatch/"; </script>';
}else if($this->ma == 3){
    echo '<script language="javascript" type="text/javascript">alert("优惠券批次序号、折扣金额、发行张数不能为空或零！");</script>';
}else if($this->ma == 22){
    echo '<script language="javascript" type="text/javascript">alert("该优惠券批次序号已存在！");</script>';
}
$arrup = $this->arrup?$this->arrup:array("no"=>false,"name"=>false,"money"=>false,"discount"=>false,"dateStart"=>false,"dateEnd"=>false,"type"=>false,"userType"=>false,"maxCount"=>false);
?>

<div id="billboy">
    <div id='userdetail'>
        添加优惠券批次
        <form action="/admini/manageuser/addbatch/" method="post">
        <table width="100%" border="1" cellpadding="0" cellspacing="0">  
            <tr>
              <td id='bf'>批次序号：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="no" id="no" value="<?php echo $arrup["no"]?$arrup["no"]:""?>"/></td>
              <td id='bf'>批次名称：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="name" id="name"  value="<?php echo $arrup["name"]?$arrup["name"]:""?>"/></td>
            </tr>
            <tr>
              <td id='bf'>底线金额：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="money" id="money" value="<?php echo $arrup["money"]?$arrup["money"]:""?>"/></td>
              <td id='bf'>折扣：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="discount" id="discount"  value="<?php echo $arrup["discount"]?$arrup["discount"]:""?>"/></td>
            </tr>
            <tr>
              <td id='bf'>开始时间：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="dateStart" id="dateStart" value="<?php echo $arrup["dateStart"]?$arrup["dateStart"]:""?>"/></td>
              <td id='bf'>结束时间：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="dateEnd" id="dateEnd"  value="<?php echo $arrup["dateEnd"]?$arrup["dateEnd"]:""?>"/></td>
            </tr>
            <tr>
              <td id='bf'>类型：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<select id="type" name="type">
                      <?php foreach ($this->couponType as $typeKey => $typeVal) { ?>
                         <option value="<?php echo $typeKey;?>" <?php echo $arrup["type"]===$typeKey?"selected":"";?>><?php echo $typeVal;?></option> 
                      <?php }?>
                  </select></td>
              <td id='bf'>用户类型：</td>
              <td id='cf' valign="middle">&nbsp;&nbsp;<input type="text" name="userType" id="userType"  value="<?php echo $arrup["userType"]?$arrup["userType"]:""?>"/></td>
            </tr>
            <tr>
              <td id='bf'>发行张数：</td>
              <td id='cf' valign="middle" colspan="3">&nbsp;&nbsp;<input type="text" name="maxCount" id="maxCount" value="<?php echo $arrup["maxCount"]?$arrup["maxCount"]:""?>"/></td>
            </tr>
            <tr>
                <td id='cf' colspan="4" align="right"><input type="hidden" name="operate" id="operate" value="add" />
                    <input type="submit" id="submit" name="submit" value="添加批次" style="background-color: #FF8312;width: 100px;height: 36px;color: white;font-size: 16px;border-radius:8px;" />&nbsp;&nbsp;
                    <input type="button" id="rehref" name="rehref" value="返回" style="background-color: #1668A4;width: 100px;height: 36px;color: white;font-size: 16px;border-radius:8px;" /></td>
            </tr>
          </table>
          </form>
    </div>
</div>
<script type="text/javascript">
    $('#no').blur(function(){
        var no = $(this).val();
        if(no != ''){
            $.post('/admini/manageuser/bybatchno', {'no':no}, function(data){
                if(data.sjtype == 2){
                    alert("该优惠券批次序号已存在！");
                    $("#no").val("");
                }
            }, 'json');
        }
    });
    $("#rehref").click(function(){
        javascript:history.go(-1);
    });
    $('#submit').click(function(){
        var startTime = $("#dateStart").val();
        var dateExpired = $("#dateEnd").val();
        var discount = $("#discount").val();
        var no = $("#no").val();
         if(no == ''){
            alert("优惠券批次序号不能为空！");
            return false;
        }else if(startTime == ''){
            alert("开始时间不能为空！");
            return false;
        }else if(dateExpired == ''){
            alert("结束时间不能为空！");
            return false;
        }else if(startTime>dateExpired){
            alert("开始时间不能大于结束时间！");
            return false;
        }else if(discount == '' || discount == 0){
            alert("优惠券的折扣不能为空或为零！");
            return false;
        }else{
            return true;
        }
    });
</script>